<!--bg-->
<!--bg-->
<?php
$table='Selling';
include('includes/before_html.php');
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

    <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
        <meta name="description" content="" />
        <meta name="keywords" content="" />
        <meta name="author" content="" />
        <?php include('includes/head.php'); ?>
        <title><?php echo $heading ?></title>

    </head>

    <body>
        <div id="wrapper">
            <?php include('includes/header.php'); ?>
            <?php include('includes/nav.php'); ?>
            <div id="content">
		<?php
		#php code for selling a book
		if (!empty($_POST['s_ISBN'])) {
		    $db = mysql_connect(db_server, $db_user, $db_password);
		    mysql_select_db($db_dbname);
		    $sql = "INSERT INTO Selling VALUES (".$getRuid.",
			                                ".$_POST['s_ISBN'].",
							".$_POST['s_price'].",
							'".$_POST['s_condition']."',
							'".$_POST['s_description']."')";
		    echo "Book Posted!";
		    
		    echo $sql;
		    mysql_query($sql);
		    
		    mysql_close($db);
		  }?>
		
                    <?php
                    echo "<h3>".$getName."'s $table Books</h3><BR>";
                    $db = mysql_connect(db_server, $db_user, $db_password);
                    mysql_select_db($db_dbname);
                    $sql="SELECT B.Title, S.ISBN, U.FirstName, U.LastName, U.Email, S.Price, S.Condition_, S.Description FROM Selling S, Books B, Users U WHERE U.RUID = S.RUID AND B.ISBN = S.ISBN AND U.RUID = " . $getRuid;
                    echo "SQL QUERY:&nbsp;".$sql."<BR><BR>";
                    $result2 = mysql_query($sql);
                    $count = mysql_num_rows($result2);
                    
                    if($count==0){
                        echo "You currently have no books for sale.";
                    }
                        
                    while ($row = mysql_fetch_array($result2)) {
                        echo "<table>";
                          {
                              echo "<tr><td><strong> Title: ". $row['Title']. " </strong></td></tr>";
			      echo "<tr><td> ISBN: ". $row['ISBN']."  </strong></td></tr>";
			      echo "<tr><td> Price: ". $row['Price']. " </td></tr>";
			      echo "<tr><td> Condition: ". $row['Price']. " </td></tr>";
			      echo "<tr><td> Description: ". $row['Description']. " </td></tr>";
			      echo "<tr><td> Seller Name: ".$row['FirstName']." ".$row['LastName']. " </td></tr>";
                              echo "<tr><td> Email: ".$row['Email']. " </td></tr>";
                          }
                        echo "</table><BR>";
                    }
                    mysql_close($db)
                    ?>
		
		<!--Sell More Books-->
		<h3>Post a Book</h3>
		  
		
		<h4>Create a new book...</h4>
		<form action="books_sell.php" method="post">
		    *ISBN: <input type="text" name="c_ISBN" /> <br>
		    *Title: <input type="text" name="c_title" /><br>
	            <input type="submit" />
		    </form>
		
		<?php
		if (!empty($_POST['c_ISBN'])) {
		    $db = mysql_connect(db_server, $db_user, $db_password);
		    mysql_select_db($db_dbname);
		    $sql = "INSERT INTO Books VALUES (  ".$_POST['c_ISBN'].",
							'".$_POST['c_title']."')";
		    echo "Book Created!";
		    
		    echo $sql;
		    mysql_query($sql);
		    
		    mysql_close($db);
		  }?>
		
		<h4>Or use an existing ISBN for a Book:</h4>
		 <?php
                    $db = mysql_connect(db_server, $db_user, $db_password);
                    mysql_select_db($db_dbname);
                    $sql="SELECT DISTINCT B.ISBN, B.Title FROM Books B";
                    echo "SQL QUERY:&nbsp;".$sql."<BR><BR>";
                    $result2 = mysql_query($sql);
                    $count = mysql_num_rows($result2);
                    
                    if($count==0){
                        echo "No books exist.";
                    }
                        
                    while ($row = mysql_fetch_array($result2)) {
                        echo "<table>";
                          {
                              echo "<tr><td> ". $row['Title']." (". $row['ISBN']. ") </td></tr>";
                          }
                        echo "</table>";
                    }
                    mysql_close($db)
                    ?> 
		
		<h4>Then post the book for sale:</h4>
		<form action="books_sell.php" method="post">
		    *ISBN: <input type="text" name="s_ISBN" /> <br>
		    Price: <input type="text" name="s_price" /><br>
		    Condition: <input type="text" name="s_condition" /><br>
		    Description: <input type="text" name="s_description" /><br>
	            <input type="submit" />
		    </form>
		
		
		
		
		
		
            </div> <!-- end #content -->
            <?php include('includes/sidebar.php'); ?>
            <?php include('includes/footer.php'); ?>
        </div> <!-- End #wrapper -->
    </body>
</html>